﻿$(document).ready(function () {

    $('div.taxi-item').hover(function () { $(this).animate({ 'background-color': '#DFEEF9' }, 200); }, function () { $(this).animate({ 'background-color': '#FFF' }, 200); });

    $('#add-review-panel > form').ajaxForm({
        beforeSerialize: beforeReviewSerialize,
        beforeSubmit: disableReviewForm,
        success: onReviewPostSuccess
    });

    settings = {
        tl: { radius: 10 },
        tr: { radius: 10 },
        bl: { radius: 10 },
        br: { radius: 10 },
        antiAlias: true,
        autoPad: true
    }
    var myBoxObject = new curvyCorners(settings, "rounded");
    myBoxObject.applyCornersToAll();

    $('.stars-wrapper').stars({
        cancelShow: false
    });

    $("input:button, input:submit").button();

    $('#forget-me-link').click(function () {
        
        //if ($('#CommenterName').val() != null && $('#CommenterName').val() != '') {

            $.get('/ru/Account/ClearAnonymousCookie', function (data) {
                $('#CommenterName').removeAttr('disabled');
                $('#CommenterName').val('');
                $('#forget-me-link').hide();
            });
       // }
    });

});

function beforeReviewSerialize() {
    $('#CommenterName').removeAttr('disabled');
    if ($('#CommenterName').val() == null || $.trim($('#CommenterName').val()) == '') {
        $('#CommenterName').addClass('input-validation-error');
        return false;
    }
    if ($('#add-review-panel textarea').val() == null || $.trim($('#add-review-panel textarea').val()) == '') {
        $('#add-review-panel textarea').addClass('input-validation-error');
        return false;
    }
    $('#add-review-panel textarea').removeClass('input-validation-error');
    $('#CommenterName').removeClass('input-validation-error');
}

function disableReviewForm() {
    
    
    $('#add-review-panel input[type="submit"]:first').button('disable');
    $('#loading-anim').show();
    
}

function onReviewPostSuccess() {
    $('#add-review-panel input[type="submit"]:first').button('enable');
    $('#add-review-panel textarea').val('');
    $('#CommenterName').attr('disabled', 'disabled');
    $('#loading-anim').hide();
    $('#forget-me-link').show();
}